<!--
Sandstorm Blackrock
Copyright (c) 2015-2016 Sandstorm Development Group, Inc.
All Rights Reserved

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<template name="billingSettings">
  {{!--
    Template for account settings. This typically:
    - Displays a list of credit cards on file, and allows adding or removing cards.
    - Displays current plan, and options for changing or canceling it.
    - Displays available credit for in-app purchases, if any.

    If the user modifies their plan, their quota is updated appropriately.
  --}}
  <section class="payment-methods">
    <h3>Payment Methods</h3>
    {{#if credit}}
      <p class="balance">Account Balance <span class="amount">${{renderCents credit}}</span>
        <span class="details">This balance will be automatically applied to future subscription
          payments and purchases.</span></p>
    {{/if}}
    <table>
      <thead>
        <tr>
          <td>Default</td>
          <td>Credit / Debit Card</td>
          <td>Expiry</td>
          <td>Delete</td>
        </tr>
      </thead>
      <tbody>
        {{#each cards}}
          <tr class="card">
            <td class="checkbox">
              <label class="{{#if isPrimary}}selected{{/if}}">
                <input type="radio" class="make-primary-card" checked="{{isPrimary}}">
              </label>
            </td>
            <td>{{brand}}: ***{{last4}}</td>
            <td>{{exp_month}}/{{exp_year}}</td><!-- TODO(soon): handle non-US formats -->
            <td><button class="delete-card" title="Delete card">X</button></td>
          </tr>
        {{/each}}
        <tr>
          <td></td>
          <td class="add-new-card {{#if showPrompt}}iframe-active{{/if}}" colspan="3">
            {{#if checkoutData}}
              <iframe class="mobile-iframe-hack {{#if showPrompt}}fullscreen{{/if}}" src="{{paymentsUrl}}/checkout#{{checkoutData}}"></iframe>
            {{/if}}
            <label><button class="add-card">+</button> Add a new credit / debit card</label>
          </td>
        </tr>
      </tbody>
    </table>
  </section>
</template>
